package quantri.login;

import java.util.ArrayList;
import java.util.Iterator;

/******************************************
 * Filename			: Group.java
 * Decription		:
 * Created date		: Jun 2, 2008
 * Author			: Phonglt
 ******************************************/
public class Group {
	private int id;
	private String fullname;
	private String folder;
	private ArrayList<Category> categories = new ArrayList<Category>();

	
	
	public Group() {}

	/**
	 * @param id
	 * @param fullname
	 * @param folder
	 */
	public Group(int id, String fullname, String folder) {
		super();
		this.id = id;
		this.fullname = fullname;
		this.folder = folder;
	}

	/**************************************
	 * Method name		: addMatchCat
	 * Return type		: boolean
	 * Decription		: thêm Cat vào nếu là không trùng
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 **************************************/
	boolean addMatchCat(Category category){
		if (this.categories.isEmpty()) {
			return this.categories.add(category);
		}
		Category lastCat = this.categories.get(this.categories.size() - 1);
		if(lastCat.getId() != category.getId()){
			return this.categories.add(category);
		}
		return false;
	}
	
	/**************************************
	 * Method name		: addMatchFunc
	 * Return type		: boolean
	 * Decription		: thêm func vào trong group match với cat của nó
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 **************************************/
	boolean addMatchFunc(Function function){
		if (this.categories.isEmpty()) {
			return false;
		}
		Category lastCat = this.categories.get(this.categories.size() - 1);
			return lastCat.addFunction(function);
	}
	/**************************************
	 * Method name		: addCategory
	 * Return type		: void
	 * Decription		: thêm 1 cat vào group
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 **************************************/
	void addCategory(Category category){
		this.categories.add(category);
	}
	
	/****************************************************
	 * Method name		: getCategories [GETTER]
	 * Return type		: ArrayList<Category>
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public ArrayList<Category> getCategories() {
		return categories;
	}

	/****************************************************
	 * Method name		: setCategories [SETTER]
	 * Return type		: void
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public void setCategories(ArrayList<Category> categories) {
		this.categories = categories;
	}

	/****************************************************
	 * Method name		: getId [GETTER]
	 * Return type		: String
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public int getId() {
		return id;
	}

	/****************************************************
	 * Method name		: setId [SETTER]
	 * Return type		: void
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public void setId(int id) {
		this.id = id;
	}

	/****************************************************
	 * Method name		: getFullname [GETTER]
	 * Return type		: String
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public String getFullname() {
		return fullname;
	}

	/****************************************************
	 * Method name		: setFullname [SETTER]
	 * Return type		: void
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	/****************************************************
	 * Method name		: getFolder [GETTER]
	 * Return type		: Group
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public String getFolder() {
		return folder;
	}

	/****************************************************
	 * Method name		: setFolder [SETTER]
	 * Return type		: void
	 * Decription		: 
	 * Created date		: Jun 2, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public void setFolder(String folder) {
		this.folder = folder;
	}
	
	public Iterator<Category> getIterator(){
		return this.categories.iterator();
	}
}
